const formidable = require('formidable');
const path = require('path')
const { Article } = require('../../model/article')
module.exports = (req, res) => {
    // 创建表单解析对象
    const form = new formidable.IncomingForm();

    // 指定存储的位置
    form.uploadDir = path.join(__dirname, "../", "../", "public", "uploads");

    // // 保留文件的后缀名
    form.keepExtensions = true;
    console.log(form)
    form.parse(req, async(err, fields, files) => {
        await Article.create({
            title: fields.title,
            author: fields.author,
            published: fields.published,
            cover: files.cover.path.split('public')[1],
            content: fields.content

        })
        res.redirect('/admin/article')
    })


}